package com.hlf.modules.merchant.common.controller;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.ReturnResult;
import com.hlf.common.validator.Assert;
import com.hlf.modules.api.entity.BusinessKind;
import com.hlf.modules.api.service.SMSService;
import com.hlf.modules.sys.controller.AbstractController;
import com.hlf.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2017/11/17.
 */
@RestController
@RequestMapping("/common")
public class CommonController extends AbstractController{

    @Autowired
    private SMSService sMSService;

    /**
     * 获取主营类目
     */
    @RequestMapping("/getKind")
    public ReturnResult getKind() {
        List<BusinessKind> businessKinds = sMSService.getKind();
        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME, businessKinds);
    }

    /**
     * 发送验证码
     * @param mobile
     * @return
     */
    @RequestMapping("/sendCode/{mobile}/{codeType}")
    public ReturnResult sendCode(@PathVariable("mobile") String mobile ,@PathVariable("codeType") String codeType) {
        Assert.isBlank(mobile, "手机号不能为空");
        Assert.isBlank(codeType, "类型不能为空");
        sMSService.sendMoblieVCode(mobile,Integer.parseInt(codeType),1);
        return ReturnResult.ok();
    }

    /**
     * 给商家发送验证码
     * @param
     * @return
     */
    @RequestMapping("/merchantCode")
    public ReturnResult sendMerchantCode() {
        SysUserEntity user = getUser();
        sMSService.sendMoblieVCode(user.getMobile(), Constants.MESSAGE_TYPE_OTHER,1);
        return ReturnResult.ok();
    }


}
